﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>上传资料</title>
<link href="${pageContext.request.contextPath}/css/themes/default/easyui.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath}/css/themes/icon.css" rel="stylesheet"></link>
<link href="${pageContext.request.contextPath}/css/themes/color.css" rel="stylesheet" />
<script src="${pageContext.request.contextPath}/script/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/script/easyui-lang-zh_CN.js"></script>
<style>
body {
	font-size: 12px;
	overflow-y: hidden;
}

th {
	font-size: 20px;
}

td {
	font-size: 18px;
}
input{
    width:282px;
}
</style>
</head>
<body class="easyui-layout" onload="initContent()" >
	<div data-options="region:'center'" >
		<div class="easyui-tabs" data-options="fit:true" >
			<div title="上传资料" style="padding:10px;">
				<form id="f" style="margin-top:4%;margin-left: 30%;" enctype="multipart/form-data">
					<tr>
						<img src="${pageContext.request.contextPath}/images/sc.png" />
						<td><span style="font-size:15px">上&nbsp;&nbsp;传：</span></td>
						<td><input type="file" name="file" style="font-size: 20px;" onchange="fileChange(this);"/>
							<td><span style="font-size:15px">上传类型:</span></td>
						<td>
							<select id="cl_up" name="classify.id">
								
							</select>
						</td>
						</td>
					</tr>
					</br>
					</br>
					<tr>
						<td>&emsp;&emsp;&emsp;
 						<input type="button" class="easyui-linkbutton c1" style="width:80px;height: 35px;margin-left:80px;font-size:20px;margin-top: 20px;" onclick="addupload()" value="上传"/>
						</td>
					</tr>
				</form>
			</div>
		</div>
	</div>
	
	<script>
		function cz(){
			window.location.reload();
		}
		
		function addupload(){
        	var formData = new FormData($("#f")[0]);
				$.ajax({
					url:"${pageContext.request.contextPath}/upload/addupload",
					type:"POST",				
					data:formData,
					dataType:"json",
					async: false,
	                cache: false,
	                contentType: false,
	                processData: false,	
					success:function(data){
       				 	alert("上传成功！！！");
						window.location.href="${pageContext.request.contextPath}/lodingupload.html";
					},
					error:function(){
						alert("上传失败！！！");
					}
				});
			}
			
			$(function(){
    		$.ajax({
    			url:"${pageContext.request.contextPath}/upload/listclassify",
    			type:"GET",
    			dataType:"json",
    			success:function(data){
    			//alert("ok");
    			$("#cl_up").empty();
    			for(var i = 0;i<data.length;i++){
  					var obj=data[i];
  					var id=obj.id;
  					var classify=obj.classify;
  					var cz='<option value='+id+'>'+classify+'</option>';	
  					$("#cl_up").append(cz);
    			}		
    			},
    			error:function(){
    				alert("error");
    			}
    		});
    	});
    	
    	
    	function fileChange(target) {	//限制文件
			var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
			var fileSize = 0;
			if(isIE && !target.files) {
				var filePath = target.value;
				var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
				var file = fileSystem.GetFile(filePath);
				fileSize = file.Size;
			} else {
				fileSize = target.files[0].size;
			}
			var size = fileSize / 6144;
			if(size > 6200) {
				alert("附件不能大于6M");
				target.value = "";
				return
			}
			var name = target.value;
			var fileName = name.substring(name.lastIndexOf(".") + 1).toLowerCase();
				if(fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif" && fileName != "txt" && fileName != "doc" && fileName != "xls") {
				alert("请选择正确的文件格式进行上传(jpg,jpeg,png,gif,txt,doc,xls)！");
				target.value = "";
				return
			}
		}
    	
	</script>
</body>
</html>
